package com.example.netty.channel.handler;

import com.example.netty.msg.IotMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 编码器
 * 将IotMsg转为ByteBuf
 */
public class MyEncoder extends MessageToByteEncoder<String> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, String iotMsg, ByteBuf byteBuf)
        throws Exception {
        byteBuf.writeBytes(iotMsg.getBytes());
    }
}
